import requests

cookies = {
    'tk': '601100958127505223',
    'sessionid': 'jxr83wimos9tnqwd8tw22kejkgf6sw16',
}

# 青花瓷抓包，headers顺序和大小写必须严格一致
headers = {
    'Host': 'match.yuanrenxue.cn',
    'Connection': 'keep-alive',
    'Content-Length': '0',
    'sec-ch-ua': '"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"',
    'sec-ch-ua-mobile': '?0',
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
    'sec-ch-ua-platform': "macOS",
    'Accept': '*/*',
    'Origin': 'https://match.yuanrenxue.cn',
    'Sec-Fetch-Site': 'same-origin',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Dest': 'empty',
    'Referer': 'https://match.yuanrenxue.cn/match/3',
    'Accept-Encoding': 'gzip, deflate, br, zstd',
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'Cookie': 'Hm_lvt_c99546cf032aaa5a679230de9a95c7db=1720709646; HMACCOUNT=9F47B428D92F550C; Hm_lvt_9bcbda9cbf86757998a2339a0437208e=1720709647; qpfccr=true; no-alert3=true; tk=601100958127505223; sessionid=1r4gcnrvb338naa18vz7nb8dwuax270r; Hm_lpvt_9bcbda9cbf86757998a2339a0437208e=1720709753; Hm_lpvt_c99546cf032aaa5a679230de9a95c7db=1720709755',
}

# 使用session保存上下文，主要是cookies
session = requests.Session()
session.headers = headers

rst = {}
max_v = 0
max_count = 0
for i in range(1, 6):
    data = {'page': i}
    url = 'https://match.yuanrenxue.cn/api/match/3?page={id}'.format(id=i)
    # 第一次请求刷新cookies
    response = session.post('https://match.yuanrenxue.cn/jssm', verify=False)
    # 第二次请求携带刷新后的cookies
    response = session.get(url, verify=False)
    values = response.json()['data']
    print(values)
    for d in values:
        if d['value'] in rst:
            rst[d['value']] += 1
        else:
            rst[d['value']] = 1

        if rst[d['value']] > max_count:
            max_v = d['value']
            max_count = rst[d['value']]

print(max_v)

